package hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import bean.EleveBean;
import bean.MailerBean;

public class MailerRepository extends GenericRepository<MailerBean, Integer> implements Serializable {

	private static final long serialVersionUID = 1L;

	public MailerBean GetById(Integer Id){
		Session s = HelperSessionFactory.getSession();
		Transaction trans = s.beginTransaction();
		Criteria criteria = s.createCriteria(MailerBean.class).add(Restrictions.eq("id_message", Id));
		MailerBean msg = (MailerBean) criteria.uniqueResult();
		s.close();
		return msg;
	}

	public List<MailerBean> GetAll(){
		Session s = HelperSessionFactory.getSession();
		Transaction trans = s.beginTransaction();
		Criteria criteria = s.createCriteria(MailerBean.class);
		List<MailerBean> lst = (List<MailerBean>) criteria.list();
		s.close();
		return lst ;
	}

	public EleveBean GetByMail(String mail){
		Session s = HelperSessionFactory.getSession();
		Transaction trans = s.beginTransaction();
		Criteria criteria = s.createCriteria(EleveBean.class).add(Restrictions.eq("email_eleve", mail));
		EleveBean msg = (EleveBean) criteria.uniqueResult();
		s.close();
		return msg ;
	}

}
